<template>
  <div>
    <a-card>
      <p>
        <a-button @click="handleAdd">新增</a-button>
      </p>
      <a-table
        :columns="columns"
        :dataSource="dataSource"
        rowKey="id"
        :loading="loading"
      >
        <template slot="deploymentId" slot-scope="text,record">
          <span v-if="record.deploymentId!=null" style="color: #7ac23c">已部署</span>
          <span v-if="record.deploymentId==null" style="color: #ff0000">未部署</span>
        </template>

        <span slot="action" slot-scope="text, record">
        <a href="javascript:;" @click="openModeler(record.id)">流程</a>
        <a-divider type="vertical"/>
        <a-dropdown>
          <a class="ant-dropdown-link">
            更多 <a-icon type="down"/>
          </a>
          <a-menu slot="overlay">
            <a-menu-item>
              <a-popconfirm title="确定部署吗?" @confirm="() => deployProcess(record.id)">
                <a v-if="record.deploymentId!=null">重新部署</a>
                <a v-else>部署</a>
              </a-popconfirm>
            </a-menu-item>
            <a-menu-item>
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
      </span>
      </a-table>
    </a-card>
    <manage-edit-model ref="modalForm" v-on:reloadPage="loadData"></manage-edit-model>
  </div>
</template>

<script>
  import { SearchListMixin } from '@/mixins/SearchListMixin'
  import ManageEditModel from '@/views/activiti/model/ManageEditModel'
  import { getAction } from '../../api/manage'

  export default {
    name: 'Manage',
    mixins: [SearchListMixin],
    components: { ManageEditModel },
    data() {
      return {
        url: {
          page: '/act/model/page',
          delete: '/act/model/deleteModel',
          deploy: '/act/model/deployProcess'
        },
        columns: [
          {
            dataIndex: 'id',
            title: '编号',
            align: 'center'
          }, {
            dataIndex: 'name',
            title: '名称',
            align: 'center'
          }, {
            dataIndex: 'key',
            title: '模型标示',
            align: 'center'
          }, {
            dataIndex: 'category',
            title: '类别',
            align: 'center'
          }, {
            dataIndex: 'deploymentId',
            title: '状态',
            align: 'center',
            scopedSlots: { customRender: 'deploymentId' }
          }, {
            dataIndex: 'createTime',
            title: '创建时间',
            align: 'center'
          }, {
            title: '最后更新时间',
            dataIndex: 'lastUpdateTime',
            align: 'center'
          }, {
            title: '操作',
            dataIndex: 'action',
            width: '150px',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ]
      }
    },
    created() {
    },
    methods: {
      openModeler(id) {
        this.$router.push({ path: '/activiti/modelerEdit', query: { modelId: id } })
      },
      deployProcess(id) {
        getAction(this.url.deploy, { modelId: id }).then(res => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData()
          } else {
            this.$message.error(res.message)
          }
        })
      }
    }
  }
</script>

<style lang="less" scoped>

</style>